import com.alibaba.dto.CallbackDidiPayRequest
import groovy.json.*
import org.apache.commons.lang.StringUtils
import redis.clients.jedis.*
import com.alibaba.moco.util.*
import com.alibaba.moco.*
import script.moco.dto.OrderInfo

/**
 * 模拟 滴滴 支付回调
 * Created by wb-lj240895 on 2016/11/1.
 */
def excute(request) {
    def slurper = new JsonSlurper()
    def params = request.getParameterMap();
    Jedis redis = RedisPoolInstance.getRedisClient()
   
    NoticeRequest req = BaseTypeUtil.mapToBean(params, NoticeRequest.class) as NoticeRequest

    def orderStr  = redis.get(req.getOrder_id())
    def orderJson = slurper.parseText(orderStr)
    orderJson.order.status = 700
    redis.set(req.getOrder_id(), JsonOutput.toJson(orderJson).toString())

    def callbackDidiPayRequest = new CallbackDidiPayRequest()
    callbackDidiPayRequest.setClientId("1")
    callbackDidiPayRequest.setSign("1")
    callbackDidiPayRequest.setTimestamp(123456l)
    callbackDidiPayRequest.setOrderId(req.getOrder_id())
    //从redis中获取info
    def info = redis.hget("DIDI.CALLBACK_INFO",req.getOrder_id())
    callbackDidiPayRequest.setCallbackInfo(info)
    callbackDidiPayRequest.setClientSecret("secret")
    callbackDidiPayRequest.setNormalDistance(20)
    callbackDidiPayRequest.setPayTime(123456l)
    callbackDidiPayRequest.setStatus(700)
    callbackDidiPayRequest.setTotalPrice(orderJson.price.total_price)
    HttpClientUtil.postPay(callbackDidiPayRequest)


    return JsonOutput.toJson("{\"message\":\"取消订单成功\"}")

}
class NoticeRequest {
    String order_id  //  yes  要确认支付的订单
}